<template>
  <NavBar>
    <img slot="left" class="back" @click="backClick" src="~assets/img/common/back.svg" alt="">
    <div slot="center" class="title">
      <span v-for="(item,index) in titles"
            :class="{active:index===currentIndex}"
            @click="navBarClick(index)">
        {{item}}
      </span>
    </div>
  </NavBar>
</template>

<script>
  import NavBar from "components/common/navbar/NavBar";

  export default {
    name: "DetailNavBar",
    props: {
      currentIndex:{
        type: Number,
        default:0
      },
      titles:{
        type: Array,
        default(){
          return ['商品', '参数', '评论', '推荐']
        }
      }
    },
    methods:{
      backClick(){
        this.$router.back()
      },
      navBarClick(index){
        this.$emit('navBarClick',index)
      }
    },
    components:{
      NavBar
    }
  }
</script>

<style scoped>
  .title{
    display: flex;
    justify-content: space-around;
    font-size: 14px;
  }
  img{
    margin-top: 8px;
  }
  .active{
    color: red;
  }
</style>